package com.ruoyi.store.service.impl;

import java.util.List;

import com.ruoyi.common.core.page.ExampleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.store.mapper.VGoodMapper;
import com.ruoyi.store.domain.VGood;
import com.ruoyi.store.service.IVGoodService;
import com.ruoyi.common.core.text.Convert;
import tk.mybatis.mapper.entity.Example;

/**
 * 商品管理 服务层实现
 *
 * @author Enzo
 * @date 2019-03-25
 */
@Service
public class VGoodServiceImpl implements IVGoodService
{
	@Autowired
	private VGoodMapper vGoodMapper;

	/**
     * 查询商品管理信息
     *
     * @param goodId 商品管理ID
     * @return 商品管理信息
     */
    @Override
	public VGood selectVGoodById(Long goodId)
	{
	    return vGoodMapper.selectByPrimaryKey(goodId);
	}

	/**
     * 查询商品管理列表
     *
     * @param vGood 商品管理信息
     * @return 商品管理集合
     */
	@Override
	public List<VGood> selectVGoodList(VGood vGood)
	{
		Example example = new Example(VGood.class);
		Example.Criteria criteria = example.createCriteria();

		ExampleUtils.andEqualTo(criteria, "goodId", vGood.getGoodId());
		ExampleUtils.andEqualTo(criteria, "goodName", vGood.getGoodName());
		ExampleUtils.andEqualTo(criteria, "goodPrice", vGood.getGoodPrice());
		ExampleUtils.andEqualTo(criteria, "goodNuit", vGood.getGoodNuit());
		ExampleUtils.andEqualTo(criteria, "goodPic", vGood.getGoodPic());
		ExampleUtils.andEqualTo(criteria, "goodStatus", vGood.getGoodStatus());
		ExampleUtils.andEqualTo(criteria, "goodDesc", vGood.getGoodDesc());
		ExampleUtils.andBetweenDateToDate(criteria, "goodCtime", vGood.getParams().get("beginGoodCtime"),vGood.getParams().get("endGoodCtime"));
		ExampleUtils.andEqualTo(criteria, "goodItemId", vGood.getGoodItemId());
		ExampleUtils.andEqualTo(criteria, "goodStoreId", vGood.getGoodStoreId());
		ExampleUtils.andEqualTo(criteria, "delState", vGood.getDelState());
		ExampleUtils.andEqualTo(criteria, "detailDescribe", vGood.getDetailDescribe());
		ExampleUtils.andEqualTo(criteria, "recommend", vGood.getRecommend());

	    return vGoodMapper.selectByExample(example);
	}

    /**
     * 新增商品管理
     *
     * @param vGood 商品管理信息
     * @return 结果
     */
	@Override
	public int insertVGood(VGood vGood)
	{
	    return vGoodMapper.insertSelective(vGood);
	}

	/**
     * 修改商品管理
     *
     * @param vGood 商品管理信息
     * @return 结果
     */
	@Override
	public int updateVGood(VGood vGood)
	{
	    return vGoodMapper.updateByPrimaryKeySelective(vGood);
	}

	/**
     * 删除商品管理对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteVGoodByIds(String ids)
	{
        Example example = new Example(VGood.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("goodId",Convert.toList(ids));
		return vGoodMapper.deleteByExample(example);
	}


    /**
     * 删除商品管理 单条信息
	 * @param goodId 删除的主键ID
     * @return
     */
    @Override
    public int deleteVGoodById(Long goodId){
        return vGoodMapper.deleteByPrimaryKey(goodId);
	}

}
